import op from '@dfeidao/atom-nodejs/db/operate';
import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';
import { IncomingHttpHeaders } from 'http';
import { productid, systemid } from '../../atom/config';
interface Message {
		filter: {
				productid: string,
				meeting_name: string,
				conference_theme: string,
				meeting_address: string,
				meeting_host: string,
				meeting_host_no: string,
				sponso_no: string,
				sponsor: string,
				start_time: string,
				finish_time: string
		}; filter1: {
				productid: string,
				pub_user_no: string,
				pub_user_name: string,
				cabinet_staff_no: string,
				department_no: string,
				dept_name: string

		}; filter2: {
				productid: string
				msg_type_no: string,
				msg_type_name: string,
				msgtemplid: string,
				msg_title: string,
				msg_cont: string,
				sender_no: string,
				sender: string,
				send_time: string
		};
		filter3: {
				productid: string,
				receiver_no: string,
				receiver: string
		}; filter4: {
				productid: string,
				param_name: string,
				param_value: string
		};
}


export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {

		// meeting_no
		const s = await doc_code(action_id, session_id, systemid, 'BM0019570', '', 1);
		// paricipants_no
		const s1 = await doc_code(action_id, session_id, systemid, 'BM0016546', '', 1);
		// msgid
		const s2 = await doc_code(action_id, session_id, systemid, 'BM0016994', '', 1);
		const { exec, insert } = op(action_id, session_id, systemid);
		// 插入数据
		insert('meeting_administration', {
				productid, meeting_no: s.result, meeting_name: message.filter.meeting_name, conference_theme: message.filter.conference_theme,
				meeting_address: message.filter.meeting_address, meeting_host: message.filter.meeting_host, meeting_host_no: message.filter.meeting_host_no,
				sponso_no: message.filter.sponso_no, sponsor: message.filter.sponsor, start_time: message.filter.start_time, finish_time: message.filter.finish_time,
				meeting_status: 1, meeting_way: 1
		});
		insert('participants', {
				productid, participants_no: s1.result, meeting_no: s.result, pub_user_no: message.filter1.pub_user_no, pub_user_name: message.filter1.pub_user_name, cabinet_staff_no: message.filter1.cabinet_staff_no,
				department_no: message.filter1.department_no, dept_name: message.filter1.dept_name
		});
		insert('msg', {
				productid, msgid: s2.result, msg_type_no: message.filter2.msg_type_no, msg_type_name: message.filter2.msg_type_name,
				msgtemplid: message.filter2.msgtemplid, msg_title: message.filter2.msg_title, msg_cont: message.filter2.msg_cont,
				sender_no: message.filter2.sender_no, sender: message.filter2.sender, send_time: message.filter2.send_time,
				msg_flag: 1, msg_status: 1
		});
		insert('msg_receiver', {
				productid, msgid: s2.result,
				receiver_no: message.filter3.receiver_no,
				receiver: message.filter3.receiver,
				is_read: 0
		});
		insert('msg_page_params', {
				productid, msgid: s2.result,
				param_name: s.result,
				param_datatype: 'string',
				param_value: s.result
		});
		const ret = await exec();
		return ret;
}
